package com.spark.gaea.security.eis;

import org.apache.shiro.codec.Base64;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.SessionIdGenerator;

import java.io.Serializable;
import java.security.SecureRandom;

public class SessionKeyGenerator implements SessionIdGenerator {
	public Serializable generateId(final Session session) {
		final SecureRandom sesssionKeyRandom = new SecureRandom();
		final byte[] sessionKeyBytes = new byte[20];
		sesssionKeyRandom.nextBytes(sessionKeyBytes);
		return Base64.encodeToString(sessionKeyBytes).replaceAll("=", "/");
	}
}
